import { loginRSA } from "@/config/settings";
import http from '@/http';
import { encryptedData } from "@/utils/encrypt";
import request from "@/utils/request";

export async function login(data) {
  if (loginRSA) {
    data = await encryptedData(data);
  }
  return request({
    url: "/login",
    method: "post",
    data,
  });
}

export function getInfo(accessToken) {
  return request({
    url: "/user/info",
    method: "post",
    data: {
      accessToken,
    },
  });
}

export function logout() {
  return request({
    url: "/logout",
    method: "post",
  });
}

export async function my_login(data) {
  // if (loginRSA) {
  //   data = await encryptedData(data);
  // }
  const res = await http.post('user/login', data)
  return res.data
}

export async function my_getInfo(accessToken) {
  const res = await http.get('user/info')
  // return {
  //   permissions: ["admin"],
  //   info: res.data,
  //   userName: "admin",
  //   avatar:
  //     "https://picsum.photos/50/50?random=a05ddedE-3dBc-5DA1-bfF2-F3D853345f08",
  // }
  // enum UserLevelEnum {
  //   //超级管理员
  //   root = -2,
  //   //系统管理员
  //   admin = -1,
  //   //领导
  //   leader = 0,
  //   //停留在区级
  //   area = 1,
  //   //停留在镇级
  //   town = 2,
  //   //停留在村级
  //   village = 3,
  // }
  let permission = ["root", "admin", "leader", "area", "town", "village"]
  return {
    code: 200,
    msg: "success", 
    data: {
      permissions: [permission[res.data.level + 2]],
      username: res.data.username,
      info: res.data,
      avatar:
        "https://picsum.photos/50/50?random=a05ddedE-3dBc-5DA1-bfF2-F3D853345f08",
    },
  };
}

export function my_logout() {
  // return request({
  //   url: "/logout",
  //   method: "post",
  // });
  return {};
}
